<!--
 * @Description: 
 * @Version: 2.0
 * @Autor: 刘世琪
 * @Date: 2021-01-30 13:41:56
 * @LastEditors: Seven
 * @LastEditTime: 2021-02-06 00:59:53
-->
<template>
    <div>
        <input type="text" v-model="username" placeholder="请输入账号">
        <input type="text" v-model="password" placeholder="请输入密码">
        <button @click="login">登录</button>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
            username:"",
            password:'',
            base_url:"http://localhost:8000/"
        }
    },
    methods: {
        login(){
            let params = {
                username:this.username,
                password:this.password,
            }
            this.axios.post(this.base_url + "login/",this.qs.stringify(params)).then(res=>{
                console.log(res.data)
                if(res.data.code== 200){
                    localStorage.setItem('username',this.username)
                    localStorage.setItem('uid',res.data.uid)
                    localStorage.setItem('role',res.data.role)
                    localStorage.setItem('right',res.data.right)
                    alert(res.data.msg)
                    this.$router.push({
                        name:"Index"
                    })
                }else{
                    alert(res.data.msg)
                }
            })
               
        } 
       

    },
    created() {

    }
}
</script>

<style scoped>

</style>
